package com.sgb.kjwl.repository.impl;

import com.sgb.kjwl.model.api.ApiSource;
import com.sgb.kjwl.model.entity.DeviceAttrEntity;
import com.sgb.kjwl.model.entity.DeviceDetailEntity;
import com.sgb.kjwl.model.entity.lease.DeviceListEntity3;
import com.sgb.kjwl.model.entity.request.MachineFilterJson3;
import com.sgb.kjwl.model.entity.supplier3.DictEntity3;
import com.swgk.core.base.model.entity.ListResponse;
import com.sgb.kjwl.repository.DeviceRepertory;
import com.swgk.core.base.api.BaseApiSource;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.base.model.preference.BasePreferenceSource;

import java.util.List;

import io.reactivex.Observable;

public class DeviceRepertoryImpl extends BaseRepertoryImpl implements DeviceRepertory {

    private final ApiSource apiSource;

    public DeviceRepertoryImpl(BaseApiSource apiSource, BasePreferenceSource preferenceSource) {
        super(apiSource, preferenceSource);
        this.apiSource = (ApiSource) apiSource;
    }

    @Override
    public Observable<DeviceDetailEntity> getDeviceDetail(String id) {
        return apiSource.getDeviceDetail(id).compose(this.<DeviceDetailEntity>rxSchedulerHelper());
    }

    @Override
    public Observable<BaseEntity<ListResponse<List<DeviceAttrEntity>>>> getDeviceAttr(String id) {
        return apiSource.getDeviceAttr(id).compose(this.<BaseEntity<ListResponse<List<DeviceAttrEntity>>>>rxSchedulerHelper());
    }

    @Override
    public Observable<BaseEntity<List<DictEntity3>>> getDeviceFilterType() {
        return apiSource.getDeviceFilterType().compose(rxSchedulerHelper());
    }

    @Override
    public Observable<BaseEntity<List<DictEntity3>>> getDeviceFilterModel(String parentNo) {
        return apiSource.getDeviceFilterModel(parentNo).compose(rxSchedulerHelper());
    }

    @Override
    public Observable<BaseEntity<List<DictEntity3>>> getMachineFilterSort() {
        return apiSource.getMachineFilterSort().compose(rxSchedulerHelper());
    }

    @Override
    public Observable<BaseEntity<List<DictEntity3>>> getDeviceFilterSpec(String id) {
        return apiSource.getDeviceFilterSpec(id).compose(rxSchedulerHelper());
    }

    @Override
    public Observable<BaseEntity<ListResponse<List<DeviceListEntity3>>>> getDeviceList3(MachineFilterJson3 machineFilterJson3) {
        return apiSource.getDeviceList3(machineFilterJson3).compose(rxSchedulerHelper());
    }
}
